/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.CompanyInfo;
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.NoteManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.ExcelUtil;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.sql.SQLException;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class ExportNote extends AbstractAction
/*    */ {
/* 26 */   private static Logger logger = Logger.getLogger(ExportNote.class.getName());
/*    */ 
/*    */   public ExportNote(AbstractHttpServlet servlet) {
/* 29 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 35 */     response.setContentType("application/force-download");
/* 36 */     response.addHeader("content-disposition", "filename=notes.xls");
/*    */ 
/* 38 */     String subjectIds = Util.getURLParameter(request
/* 39 */       .getParameter("subjectIds"));
/* 40 */     String title = Util.getURLParameter(request.getParameter("title"));
/* 41 */     int dealId = Util.getURLIntParameter(request.getParameter("dealId"));
/*    */ 
/* 43 */     NoteManager manager = new NoteManager();
/* 44 */     List result = null;
/*    */ 
/* 46 */     User loginUser = getLoginUser(request);
/*    */ 
/* 48 */     CompanyInfo company = super.getCompany(loginUser.companyId);
/*    */     try {
/* 50 */       if (dealId > 0)
/* 51 */         result = manager.listDealNotes(dealId, true);
/*    */       else {
/* 53 */         result = manager.listCustomerNotes(subjectIds, -1, 0);
/*    */       }
/* 55 */       if ((result != null) && (result.size() > 0))
/* 56 */        for (Object itemO : result) {
                Map item = (Map)itemO;
/* 57 */           String createUserName = Util.getUserNameById(
/* 58 */             (String)item.get("CreateUserId"), company.users);
/* 59 */           item.put("CreateUserName", createUserName);
/*    */         }
/*    */     }
/*    */     catch (DBException e) {
/* 63 */       logger.warn("export note failed", e);
/*    */     } catch (SQLException e) {
/* 65 */       logger.warn("export note failed", e);
/*    */     }
/*    */ 
/* 68 */     String[] heads = { "备注内容", "备注时间", "下次联系时间", "创建者", "创建时间" };
/* 69 */     String[] headsKey = { "Remark", "NoteDate", "NextContactDate", 
/* 70 */       "CreateUserName", "CreateDate" };
/*    */ 
/* 72 */     ExcelUtil.export(title + " 的联系记录", heads, headsKey, result, null, 
/* 73 */       response.getOutputStream());
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ExportNote
 * JD-Core Version:    0.6.1
 */